#region License
///License Begin
///This program has been developed by: Rodolfo Grave de Peralta, 
///Copyright (C) 2007 Rodolfo Grave de Peralta
///This program is free software; you can redistribute it and/or modify
///it under the terms of the GNU General Public License as published by
///the Free Software Foundation; either version 2 of the License, or
///(at your option) any later version.
///
///This program is distributed in the hope that it will be useful,
///but WITHOUT ANY WARRANTY; without even the implied warranty of
///MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
///GNU General Public License for more details.
///
///You should have received a copy of the GNU General Public License
///along with this program; if not, write to the Free Software
///Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
///License End
#endregion

using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace TEAM.TimeTracking.Model
{
    public class TaskExecution : INotifyPropertyChanged
    {

        public TaskExecution(Task t, DateTime aStartTime)
        {
            if (t == null)
            {
                throw new ArgumentNullException("Task t");
            }
            task = t;
            startTime = aStartTime;
        }

        protected Task task;

        public Task Task
        {
            get { return task; }
            set 
            { 
                task = value;
                OnPropertyChanged("Task");
            }
        }

        protected DateTime startTime;

        public DateTime StartTime
        {
            get { return startTime; }
            set 
            { 
                startTime = value;
                OnPropertyChanged("StartTime");
                OnPropertyChanged("Duration");
            }
        }

        protected DateTime? endTime;

        public DateTime? EndTime
        {
            get { return endTime; }
            set 
            { 
                endTime = value;
                OnPropertyChanged("EndTime");
                OnPropertyChanged("Duration");
            }
        }

        public TimeSpan? Duration
        {
            get
            {
                TimeSpan? result = null;
                if (EndTime == null)
                {
                    result = DateTime.Now.Subtract(StartTime);
                }
                else
                {
                    result = EndTime.Value.Subtract(StartTime);
                }
                return result;
            }
        }

        protected string description;

        public string Description
        {
            get { return description; }
            set 
            { 
                description = value;
                OnPropertyChanged("Description");
            }
        }

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
